-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block_while! macro that blocks while another expression evaluates to true #18
base: master
Are you sure you want to change the base?
Conversation
block_while! blocks as for the operation to finish as long as the expression $c evaluates to true.
This sounds fine to me. However it has been lying around for quite a while. |
Looks mostly okay to me. I do find the "rewrapping" a bit weird. Can't we just do:
|
I agree. Good point. match $e {
Err($crate::Error::WouldBlock) => {
if !$c {
break Err($crate::Error::WouldBlock);
}
},
Err(e) => {
#[allow(unreachable_code)]
break Err(e)
},
Ok(x) => break Ok(x),
} @kellerkindt Would you do this change, rebase to master and add an example to the documentation? |
Nope, I meant |
Interesting! I assumed the matching branch would move it and thus drop it on |
I am using this macro derivative for an private project for a while now and decided to see whether others (like you) can make use of it as well. Basically it adds a condition to
block!
so that it does not block indefinitely. This allows code like this:The operation is still blocking but in this case has a timeout for the whole operation.